<template>
  <view class="container" v-if="!loading">
    <oldBasic :result="baziResult"></oldBasic>
    <activity-box :positionId="102"></activity-box>
    <oldSizhu :result="baziResult"></oldSizhu>
    <oldShiniandayun :result="baziResult"></oldShiniandayun>
    <oldNav @itemClick="itemChange"></oldNav>
    <!-- <basic :result="baziResult" @itemClick="itemChange"></basic> -->
    <view v-if="itemindex == 0" class="item-box">
      <!-- <sizhu :result="baziResult"></sizhu> -->
      <chenggu :result="baziResult"></chenggu>
      <tianganliuyi :result="baziResult"></tianganliuyi>
      <gongwei :result="baziResult"></gongwei>
      <liuqin :result="baziResult"></liuqin>
      <bazixiji :result="baziResult"></bazixiji>
      <shensha :result="baziResult"></shensha>
    </view>
    <view v-if="itemindex == 1" class="item-box">
      <dayunsizhu :result="baziResult"></dayunsizhu>
      <liuniandayun :result="baziResult"></liuniandayun>
      <dayun :result="baziResult"></dayun>
      <liunian :result="baziResult"></liunian>
      <liuyue :result="baziResult"></liuyue>
      <liuri :result="baziResult"></liuri>
    </view>
    <view v-if="itemindex == 2" class="item-box">
      <wangshuai :result="baziResult"></wangshuai>
      <xijiyongshen :result="baziResult"></xijiyongshen>
      <canggangeshu :result="baziResult"></canggangeshu>
      <xiantiancaifu :result="baziResult"></xiantiancaifu>
      <dayuncaifu :result="baziResult"></dayuncaifu>
      <liuniancaifu :result="baziResult"></liuniancaifu>
      <xiantianjiankang :result="baziResult"></xiantianjiankang>
      <wuxinggeshu :result="baziResult"></wuxinggeshu>
    </view>
    <activity-box :positionId="103"></activity-box>
    <!-- <uni-popup ref="popup" type="center" :is-mask-click="false">
      <view class="pop-box">
        <image class="popup-img" mode="heightFix" :src="popInfo.imageLinks" @click="popTarget(popInfo)" />
        <image class="popup-close" mode="heightFix" src="@/static/images/bazi/close.png" @click="closePop" />
      </view>
    </uni-popup> -->
  </view>
</template>
<script>
import { getMallListApi } from "@/http/api";
import { getBaziResultApi } from "@/http/api/bazi/api";
import basic from "./components/basic.vue";
import sizhu from "./components/sizhu.vue";
import gongwei from "./components/gongwei.vue";
import liuqin from "./components/liuqin.vue";
import bazixiji from "./components/bazixiji.vue";
import shensha from "./components/shensha.vue";
import wangshuai from "./components/wangshuai.vue";
import xijiyongshen from "./components/xijiyongshen.vue";
import wuxinggeshu from "./components/wuxinggeshu.vue";
import canggangeshu from "./components/canggangeshu.vue";
import dayunsizhu from "./components/dayunsizhu.vue";
import liuniandayun from "./components/liuniandayun.vue";
import dayun from "./components/dayun.vue";
import liunian from "./components/liunian.vue";
import liuyue from "./components/liuyue.vue";
import liuri from "./components/liuri.vue";
import oldBasic from "./components/old-basic.vue";
import oldSizhu from "./components/old-sizhu.vue";
import oldNav from "./components/old-nav.vue";
import oldShiniandayun from "./components/old-shiniandayun.vue";
import xiantiancaifu from "./components/xiantiancaifu.vue";
import dayuncaifu from "./components/dayuncaifu.vue";
import liuniancaifu from "./components/liuniancaifu.vue";
import xiantianjiankang from "./components/xiantianjiankang.vue";
import chenggu from "./components/chenggu.vue";
import tianganliuyi from "./components/tianganliuyi.vue";
export default {
  components: {
    basic,
    sizhu,
    gongwei,
    liuqin,
    bazixiji,
    shensha,
    wangshuai,
    xijiyongshen,
    wuxinggeshu,
    canggangeshu,
    dayunsizhu,
    liuniandayun,
    dayun,
    liunian,
    liuyue,
    liuri,
    oldBasic,
    oldSizhu,
    oldNav,
    oldShiniandayun,
    xiantiancaifu,
    dayuncaifu,
    liuniancaifu,
    xiantianjiankang,
    chenggu,
    tianganliuyi,
  },
  data() {
    return {
      loading: true,
      baziResult: {},
      itemindex: 0,
      popInfo: "",
    };
  },
  mounted() {
    let query = this.$route.query;
    uni.showLoading({
      mask: true,
      title: "加载中",
    });
    let { name, sex, area, year, month, day, hour, minute, isSolar } = query;
    getBaziResultApi({
      userName: name,
      birthDay: `${year}-${month}-${day} ${hour}:${minute}`,
      districtGeocode: area,
      sex: sex == "0" ? "男" : "女",
      solar: isSolar == "1",
    }).then((res) => {
      if (res.code == 200) {
        this.baziResult = res.data;
        uni.hideLoading();
        this.loading = false;
        this.getPopInfo();
      } else {
        uni.showToast({
          title: res.msg,
          icon: "none",
        });
      }
    });
  },
  methods: {
    itemChange(e) {
      this.itemindex = e.index;
    },
    closePop() {
      this.$refs.popup.close();
    },
    getPopInfo() {
      getMallListApi({
        pageNum: 1,
        pageSize: 999,
        status: 1,
        category: 96,
      }).then((res) => {
        if (res.code == 200 && res.rows.length > 0) {
          let num = uni.getStorageSync("concernAppTips") || 0;
          if (num > 2) return;
          this.$refs.popup.open();
          this.popInfo = res.rows[0];
          uni.setStorageSync("concernAppTips", ++num);
        }
      });
    },
    popTarget(item) {
      if (item.skipLinks && item.skipLinks != "") {
        window.location.href = item.skipLinks;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  height: 100%;
  width: 100%;
  overflow-y: scroll;
  position: relative;
}

.item-box {
  box-sizing: border-box;
  width: 100%;
}
.pop-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.popup-img {
  width: 600rpx;
  height: 600rpx;
  margin-bottom: 40rpx;
}
.popup-close {
  width: 80rpx;
  height: 80rpx;
}
</style>
